package com.botao.cms.config;

import com.botao.cms.CMSApplication;
import com.botao.cms.Interceptors.AuthInterceptors;
import com.botao.cms.Interceptors.LoginInterceptors;
import org.springframework.boot.system.ApplicationHome;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginInterceptors()).addPathPatterns("/admin/**");
        registry.addInterceptor(new AuthInterceptors()).addPathPatterns("/admin/sys/**");
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/upload/**")
                .addResourceLocations("file:" + new ApplicationHome(CMSApplication.class).getDir().getPath() + "/upload/");
    }
}
